<?php
class C_Login extends C_Abstract
{
    public function indexAction()
    {
        $this->smt->display('login.html');
    }
    
    public function logoutAction()
    {
        session_destroy();
        \SF\Controller\Router::redirect('/?c=login');
    }
    
    public function dologinAction()
    {
        $status = 0;
        $message = '';

        require_once APP_ADMIN . '/input/login.php';
        $input = new Input_Login(getPost());
        // 表单有效性
        if ($input->isValid()) {
            $sql = 'SELECT password FROM t_admin_user WHERE username="'. $input->username .'"';
            $password = $this->db->fetchOne($sql);
            if ($password && $password == strtolower(md5($input->password))) {
                $status = 1;
                $_SESSION[self::SESS_ADMIN_NAME] = $input->username;
            } else {
                $message = '用户名或密码错误';
            }
        } else {
            $message = $input->getMessage();
        }

        if ($status) {
            \SF\Controller\Router::redirect('/');
        } else {
            alert($message);
            //$this->smt->assign('error_msg', $message);
            //$this->smt->display('login_error.html');
        }
    }
}